package com.dankegongyu.lib.share.bean;

import android.app.Activity;

import com.dankegongyu.lib.share.DKShareButton;
import com.dankegongyu.lib.share.DKShareCallback;
import com.dankegongyu.lib.share.DKShareInterceptor;
import com.dankegongyu.lib.share.DK_SHARE_MEDIA;

import java.util.Arrays;
import java.util.List;

import androidx.annotation.NonNull;

/**
 * @author wupuquan
 * @version 1.0
 * @since 2018/3/12 17:24
 */
public abstract class DKShareObject<T extends DKShareObject> {

    private Activity activity;
    private String title;
    private String subTitle;
    private String shareTitle;
    private String shareContent;
    private List<DK_SHARE_MEDIA> platforms;
    private List<DKShareButton> customPlatforms;
    private DKShareInterceptor<T> shareInterceptor;

    DKShareObject(Activity activity) {
        this.activity = activity;
    }

    /**
     * 分享面板标题
     *
     * @param title 如：分享评价
     */
    public T setTitle(String title) {
        this.title = title;
        //noinspection unchecked
        return (T) this;
    }

    /**
     * 分享面板副标题
     *
     * @param subTitle 如：分享到 | 蛋壳不错，分享一波！
     */
    public T setSubTitle(String subTitle) {
        this.subTitle = subTitle;
        //noinspection unchecked
        return (T) this;
    }

    /**
     * 分享标题
     *
     * @param shareTitle 如：蛋壳公寓
     */
    public T setShareTitle(String shareTitle) {
        this.shareTitle = shareTitle;
        //noinspection unchecked
        return (T) this;
    }

    /**
     * 分享内容
     *
     * @param shareContent 住蛋壳，有所居有好居
     */
    public T setShareContent(String shareContent) {
        this.shareContent = shareContent;
        //noinspection unchecked
        return (T) this;
    }

    /**
     * 分享平台
     */
    public T setPlatforms(DK_SHARE_MEDIA... platforms) {
        this.platforms = Arrays.asList(platforms);
        //noinspection unchecked
        return (T) this;
    }

    /**
     * 自定义分享平台
     *
     * @param customPlatforms {@link DKShareButton}
     */
    public T setCustomPlatforms(DKShareButton... customPlatforms) {
        this.customPlatforms = Arrays.asList(customPlatforms);
        //noinspection unchecked
        return (T) this;
    }

    /**
     * 分享拦截，主要针对新浪微博，需要在分享内容后面加@XXX
     *
     * @param shareInterceptor 分享拦截器{@link DKShareInterceptor}
     */
    public T setInterceptor(DKShareInterceptor<T> shareInterceptor) {
        this.shareInterceptor = shareInterceptor;
        //noinspection unchecked
        return (T) this;
    }

    /**
     * 调起分享面板
     */
    public abstract void show();

    /**
     * 调起分享面板
     *
     * @param shareCallback 分享回调{@link DKShareCallback}
     */
    public abstract void show(DKShareCallback shareCallback);

    /**
     * 直接分享到某个平台，不调分享面板
     *
     * @param dk_share_media 分享平台{@link DK_SHARE_MEDIA}
     */
    public abstract void shareDirect(DK_SHARE_MEDIA dk_share_media);

    /**
     * 直接分享到某个平台，不调分享面板
     *
     * @param dk_share_media 分享平台{@link DK_SHARE_MEDIA}
     * @param shareCallback  分享回调{@link DKShareCallback}
     */
    public abstract void shareDirect(DK_SHARE_MEDIA dk_share_media, DKShareCallback shareCallback);

    public Activity getActivity() {
        return activity;
    }

    public String getTitle() {
        return title;
    }

    public String getSubTitle() {
        return subTitle;
    }

    public String getShareTitle() {
        return shareTitle;
    }

    public String getShareContent() {
        return shareContent;
    }

    public List<DK_SHARE_MEDIA> getPlatforms() {
        return platforms;
    }

    public List<DKShareButton> getCustomPlatforms() {
        return customPlatforms;
    }

    public DKShareInterceptor<T> getShareInterceptor() {
        return shareInterceptor;
    }

    public abstract DKMediaType getShareMedia();

    public enum DKMediaType {
        IMAGE {
            @NonNull
            @Override
            public String toString() {
                return "0";
            }
        },
        WEB {
            @NonNull
            @Override
            public String toString() {
                return "1";
            }
        },
        TEXT {
            @NonNull
            @Override
            public String toString() {
                return "2";
            }
        };

        private DKMediaType() {
        }
    }
}

